package com.zhonghui.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.model.Product;
import com.zhonghui.service.ProductService;
import com.zhonghui.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @PostMapping("/getHot")
    public FwResult getHot(@RequestBody PageVO p){
        IPage<Product> page = productService.lambdaQuery().eq(Product::getHotFlag, 1)
                .page(p.getPage());
        return FwResult.ok(page);
    }

    @PostMapping
    public FwResult get(@RequestBody PageVO p){
        IPage<Product> page = productService
                .page(p.getPage());
        return FwResult.ok(page);
    }

    @GetMapping("{id}")
    public FwResult get(@PathVariable("id") int id){
        return FwResult.ok(productService.getById(id));
    }
}
